import React, { Component } from 'react'
import { goodsSearch } from '../api/classify'
import { Button } from 'antd-mobile'
import { connect } from 'react-redux'

class GoodsList extends Component {
    state = {
        list: []
    }
    addCarTtem = (item) => {
        console.log(item)
        this.props.dispatch({ type: "ADD_CAR_ITEM", item })
    }
    render() {
        const { list } = this.state
        return (
            <div>
                <button onClick = {() => {
                    this.props.history.go(-1)
                }}>返回</button>
                <ul>
                    {
                        list.map(item => {
                            return <li className="goods-li" key = { item.goods_id }>
                                <div className="goods-left">
                                    <img src = { item.goods_small_logo } alt="" />
                                </div>
                                <div className="goods-right">
                                    { item.goods_name }
                                    <Button onClick = {() => {
                                        this.addCarTtem(item)
                                    }}>添加</Button>
                                </div>
                            </li>
                        })
                    }
                </ul>
            </div>
        )
    }
    componentDidMount() {
        goodsSearch({ cid: this.props.location.state.cid }).then(res => {
            this.setState({
                list: res.data.message.goods
            })
        })
    }
}

const mapStateToProps = () => {
    return {
        
    }
}


export default connect(mapStateToProps)(GoodsList)
